/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package servlets.register.student;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import AO.Login;
import AO.Student;
import javax.servlet.RequestDispatcher;

/**
 *
 * @author FRIENDS
 */
@WebServlet(name = "Addtostudentbean", urlPatterns = {"/student/registration/addtostudentbean"})
public class Addtostudentbean extends HttpServlet {

   
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        
        PrintWriter out=response.getWriter();
        
        Student st=new Student();
        Login login=new Login();
        
        login.setUserid(request.getParameter("userid"));
        login.setPassword(request.getParameter("password"));
        login.setType("student");
        login.setEmail(request.getParameter("email"));
        login.setIsEnabled(true);
        login.setIsLoggedin(true);
        
        st.setFname(request.getParameter("fname"));
        st.setLname(request.getParameter("lname"));
        st.setGender(request.getParameter("gender"));
        st.setQualification(request.getParameter("qualification"));
        st.setUserid(request.getParameter("userid"));
        st.setPassword(request.getParameter("password"));
        st.setEmail(request.getParameter("email"));
        st.setMobile(request.getParameter("mobile"));
        
        
        
        try{DAO.LoginDAO.save(login);System.out.println("login added");DAO.StudentDAO.save(st);}catch(Exception e){out.println(e);}
        
        
        request.getSession().invalidate();
         request.getSession().setAttribute("logindata", login);
        request.getSession().setAttribute("userdata", st);
       
        
        RequestDispatcher disp=request.getRequestDispatcher("profilepicupload.html");
        disp.forward(request, response);
        
        
    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}
